<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        车位使用添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <style>
        .imgs{display: none;}
    </style>

</head>
<body>
<div class="x-body">
    <form class="layui-form layui-form-pane" action="/device/add.do" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="id" value="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>所属小区
                        </label>
                        <div class="layui-input-block">
                            <select name="villageId" id="community_id">
                                <option >请选择</option>
                                <c:forEach items="${villages}" var="village">
                                    <option value="${village.id}">${village.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>设备名称
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="name" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>品牌
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="logo" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>购买单价(￥)
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="price" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>购买数量
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="count" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>购买日期
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="expectTime" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>预计使用年限(年)
                        </label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="buyTime" placeholder="开始时间" id="LAY_demorange_s" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" type="submit" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <div style="height:100px;"></div>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="/js/x-layui.js" charset="utf-8"></script>
<script>
    layui.use(['laydate','element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        form.render();
        var start = {
            min: '1999-06-16 23:59:59'
            ,max: laydate.now()
            ,istoday: false
            ,choose: function(datas){
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        };
        document.getElementById('LAY_demorange_z').onclick = function(){
            start.elem = this;
            laydate(start);
        };

        //监听提交
        form.on('submit(add)', function(data){
            var name=$("input[name='name']").val();
            var logo=$("input[name='logo']").val();
            var price=$("input[name='price']").val();
            var count=$("input[name='count']").val();
            var expectTime=$("input[name='expectTime']").val();
            var buyTime=$("input[name='buyTime']").val();
            if(name==""){
                layer.msg('设备名称不能为空',{icon:5,time:2000});return false;
            }
            if(logo==""){
                layer.msg('品牌名称不能为空',{icon:5,time:2000});return false;
            }
            if(price==""){
                layer.msg('购买单价不能为空',{icon:5,time:2000});return false;
            }
            if(!(/^(?!0+(\.0+)?$)\d+(\.\d+)?$/.test(price))){
                layer.msg('购买单价不符合规则',{icon:5,time:2000});return false;
            }
            if(count==""){
                layer.msg('购买数量不能为空',{icon:5,time:2000});return false;
            }
            if(!(/(^[1-9]\d*$)/.test(count))){
                layer.msg('购买数量不符合规则',{icon:5,time:2000});return false;
            }
            if(expectTime==""){
                layer.msg('购买时间不能为空',{icon:5,time:2000});return false;
            }
            if(buyTime==""){
                layer.msg('预计使用时间不能为空',{icon:5,time:2000});return false;
            }

            var data=data.field;
            $.ajax({
                type:"post",
                url:"/device/${url}",
                data:data,
                dataType:"json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;

                    }
                    else{
                        layer.msg(data.info,{icon:5,time:2000});return false;
                    }
                }
            });
        });
    })
</script>
</body>
</html>